<!DOCTYPE html>
<html lang="zh-CN">
<meta charset="utf-8" />
<head>
<title>添加CBD环境 <?php echo $this->config->item('title');?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"	href="<?php echo base_url()?>public/css/bootstrap.min.css">
<link rel="stylesheet" href="<?php echo base_url()?>public/css/style.css">
</head>
<body>
	<script src="<?php echo base_url()?>public/js/jquery-2.0.2.min.js"></script>
	<script src="<?php echo base_url()?>public/js/bootstrap.min.js"></script>
	<script src="<?php echo base_url()?>public/js/bootstrap-confirm.js"></script>
	<script src='<?php echo base_url()?>public/js/bootbox.min.js'></script>
	<script src='<?php echo base_url()?>public/js/jquery.form.js'></script>
	<script src='<?php echo base_url()?>public/js/ssi_common.js'></script>
	<script type="text/javascript">
	jQuery(function($) {

		$('#main_from').ajaxForm({
			dataType:  'json',
			beforeSubmit:  showRequest,
			success:   processJson
		});
	
		function showRequest(formData, jqForm, options) {
		}
	
		function processJson(data) {
			if (data.result==false) {
				bootbox.alert(data.message, function() {
				});
				$('button[type="button"]').removeClass('disabled');
			}else{
				window.location.href=data.redirect_url;
			}
		}
	});
	</script>
	<div role="navigation" class="navbar navbar-inverse navbar-fixed-top">
		<div class="container">
			<div class="navbar-header">
				<a class="navbar-brand">SSI后台管理系统</a>
			</div>
			<div class="collapse navbar-collapse navbar-right">
				<ul class="nav navbar-nav">
					<li><a href="<?php echo base_url()?>" class="navbar-link">首页</a></li>
					<li><a href="<?php echo base_url()."index.php/common_login_user_set"?>" class="navbar-link">超级管理员</a></li>
					<li><a href="<?php echo base_url()?>index.php/common_login_manage/logout" class="navbar-link">退出</a></li>
				</ul>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-xs-3">
				<?php echo $user_menu?>
			</div>
			<div class="col-md-9">
				<div class="panel panel-default">
					<div class="panel-heading">添加CBD环境</div>
					<div class="panel-body">
						<form method="post" enctype="multipart/form-data" id="main_from" action="<?php echo base_url()."index.php"?>/media_env_urban_manage/save_env_urban_cbd"
							class="form-horizontal">
							<div id="env_name" class="form-group">
								<label for="env_name" class="control-label col-sm-3">CBD名称</label>
								<div class="col-sm-5">
									<input id="env_name" type="text" name="env_name" required
										onblur="checkName()" class="form-control">
								</div>
								<span class='help-block'>必填</span>
							</div>
							<div id="Parents" class="form-group">
								<label for="parent1" class="control-label col-sm-3">所属地区</label>
								<div id="parents" class="col-sm-5">
									<select id="parent1" name="province"
										onchange="onParent1Changed()" class="form-control">
										<option	value="0">无</option>
										<?php if ($top_regions!=null) {
												foreach ($top_regions as $region){	?>
										<option value="<?php echo $region['region_id']?>"><?php echo $region['region_name']?></option>
										<?php 
											}
										}?>
										
									</select>
								</div>
								<span class='help-block'>必选</span>
							</div>
							<div class="form-group">
								<label for="location" class="control-label col-sm-3">具体位置</label>
								<div class="col-sm-5">
									<input type="text" name="location" class="form-control">
								</div>
							</div>
							<div class="form-group">
								<label for="distribution_map" class="control-label col-sm-3">媒体分布图</label>
								<div class="col-sm-5">
									<input type="file" name="distribution_map" class="form-control">
								</div>
							</div>
							<div class="form-group">
								<label for="sketch_map" class="control-label col-sm-3">位置示意图</label>
								<div class="col-sm-5">
									<input type="file" name="sketch_map" class="form-control">
								</div>
							</div>
							<div class="form-group">
								<label for="building" class="control-label col-sm-3">主要建筑</label>
								<div class="col-sm-5">
									<input type="text" name="building" class="form-control">
								</div>
							</div>
							<div class="form-group">
								<label for="main_road" class="control-label col-sm-3">主干道</label>
								<div class="col-sm-5">
									<input type="text" name="main_road" class="form-control">
								</div>
							</div>
							
							<div class="form-group">
								<label for="enterprise" class="control-label col-sm-3">大型企业</label>
								<div class="col-sm-5">
									<input type="text" name="enterprise" class="form-control">
								</div>
							</div>
							<div class="form-group">
								<label for="hotel" class="control-label col-sm-3">四星级以上酒店</label>
								<div class="col-sm-5">
									<input type="text" name="hotel" class="form-control">
								</div>
							</div>
							<div class="form-group">
								<label for="subway_station" class="control-label col-sm-3">地铁枢纽</label>
								<div class="col-sm-5">
									<input type="text" name="subway_station" class="form-control">
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-offset-3 col-sm-10">
									<button type="button" onclick='from_check_login($("#main_from"),"<?php echo base_url()?>")' class="btn btn-primary">添加</button>
									<a href="javascript:void()" onclick='history.back()' >返回</a>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
			<script>
			function getId() {
					 var id = $('#id');
					 if (id.length == 0) {
					  return null;
					 }
					 return id.val();
					}
	function ajaxParam(params) {
	 var id = getId();
	 if (id) {
	  params.originalId = id;
	 }
	 return params;
	}
function showErrorIf(condition, groupid, errmsg) {
 var group = $("#" + groupid);
 $("#" + groupid + ' .help-block').remove();
 if (condition) {
  group.append("<span class='help-block'>" + errmsg + "</span>");
  group.addClass('has-error');
 } else {
  group.removeClass('has-error');
 }
}
function checkRegion() {
 var index = $("#parent1").get(0).selectedIndex;
 showErrorIf(index == 0, 'Parents', '必须填写所属区域');
}
function checkName() {
 var params = ajaxParam({ name: name });
 $.getJSON("/api/hasvendor", params, function(json){
  showErrorIf(json.length > 0, 'Name', '该公司名称已存在');
 });
}
$(function($) {
 $("form").submit(function(e){
  checkRegion();
  var errors = $('.form-group.has-error');
  if (errors.length > 0) {
   e.preventDefault();
   return;
  }
  $('button[type="button"]').addClass('disabled');
 });
});	</script>
			<script>function onParent1Changed(){
 checkRegion();
 var parent1 = $("#parent1");
 var parent2 = $("#parent2");
 parent2.remove();
 var parent3 = $("#parent3");
 parent3.remove();
 var index = $("#parent1").get(0).selectedIndex;
 if (index == 0) {
  return;
 }
 var parentid = parent1.val();
 $.getJSON("<?php echo base_url()."index.php/sys_region_manage/get_regions"?>", { region_id: parentid }, function(json){
  if (json.length == 0) {
   return;
  }
  $("#parents").append("<select class='span5 form-control' id='parent2' name='city' onchange='onParent2Changed()'></select>");
  var parent2 = $("#parent2");
  parent2.append("<option value='0'>无</option>");
  for(var i = 0, len = json.length; i<len; ++i){
   var region = json[i];
   parent2.append("<option value=" + region.region_id + ">" + region.region_name + "</option>");
  }
 });
}
function onParent2Changed(){
 var parent2 = $("#parent2");
 var parent3 = $("#parent3");
 parent3.remove();
 var index = $("#parent2").get(0).selectedIndex;
 if (index == 0) {
  return;
 }
 var parentid = parent2.val();
 $.getJSON("<?php echo base_url()."index.php/sys_region_manage/get_regions"?>", { region_id: parentid}, function(json){
	  if (json.length == 0) {
	   return;
	  }
	  $("#parents").append("<select class='span5 form-control' id='parent3' name='region'></select>");
	  var parent3 = $("#parent3");
	  parent3.append("<option value='0'>无</option>");
	  for(var i = 0, len = json.length; i<len; ++i){
	   var region = json[i];
	   region_type="";
	   if(region.region_type=="10"){
		   region_type="(中心城区)";
		}
		if(region.region_type=="20"){
		   region_type="(周边城区)";
		}
		if(region.region_type=="30"){
			region_type="(下属县市)";
		}
		if(region.region_type=="40"){
		   region_type="(下属镇区)";
		}
	   parent3.append("<option value=" + region.region_id + ">" + region.region_name+region_type + "</option>");
	  }
	 });
}</script>
		</div>
	</div>
<div  class="back-to" id="toolBackTop">
	<a title="返回顶部" onclick="window.scrollTo(0,0);return false;" href="#top" class="back-top">
	返回顶部</a>
	<a title="返回底部" onclick="window.scrollTo(0,document.body.scrollHeight);return false;" href="#bottom" class="back-bottom">
	返回底部</a>
</div>
</body>
</html>
